package com.learn.gateway.filter;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

/** 转发前请求处理 per */
@Component
public class TokenAuthorizeFilter extends ZuulFilter {

	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public String filterType() {
		return FilterConstants.PRE_TYPE;
	}

	@Override
	public int filterOrder() {
		return FilterConstants.PRE_DECORATION_FILTER_ORDER - 1;
	}

	@Override
	public Object run() {
		RequestContext currentContext = RequestContext.getCurrentContext();
		HttpServletRequest request = currentContext.getRequest();
		String token = request.getParameter("token");
		if (StringUtils.isBlank(token)) {
			//currentContext.setSendZuulResponse(false);
			//currentContext.setResponseStatusCode(HttpStatus.SC_UNAUTHORIZED);
		}
		@SuppressWarnings("unused")
		String authorize = request.getHeader("authorize");
//		System.err.println(authorize);
		return null;
	}

}
